﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TranBuild.aspx.cs" Inherits="ZLDC.Estate.UM.TranBuild" %>

<%@ Register src="../UserControl/Estate_Autocomplete.ascx" tagname="Estate_Autocomplete" tagprefix="uc1" %>

<%@ Register src="../UserControl/Build_List.ascx" tagname="Build_List" tagprefix="uc2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>删除/合并栋阁</title>
    <link href="../css/main.css" rel="stylesheet" type="text/css" />
    <script src="../js/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>

    <link href="../js/jquery/style/jquery.hiAlerts.css" rel="stylesheet" type="text/css" />

    <script src="../js/jquery/jquery.hiAlerts-min.js" type="text/javascript"></script>
    
    <script src="../js/jquery.autocomplete/jquery.autocomplete.min.js" type="text/javascript"></script>

    <link href="../js/jquery.autocomplete/jquery.autocomplete.css" rel="stylesheet" type="text/css" />

    <script src="../js/LexunJS.js" type="text/javascript"></script>

    <base  target="_self"/>
   
    <script type="text/javascript" language="javascript">
        var currentPage = 1; // 当前页
        var pageSize = 15; // 每页显示多少条
        var pageall = 0; // 总页数
        var total = 0; // 总记录数        
        function Search() {
            var name = $("#hEstateName").val();     // 楼盘名称
            if (name == "") {
                alert("选输入楼盘名称");
                return;
            }
            loadBuild(); //加载栋阁
            ShowBuildList(currentPage); //加载栋阁列表
        }
        
        //加载栋阁
        function loadBuild() {
            var ename = $("#hEstateName").val();        // 楼盘名称
            

            if ((typeof (ename) == "undefined"))
                ename = "";

            $.ajax({
                type: 'POST',
                url: '../Handler/HandlerIndex.ashx',
                data: 'act=buildlist_byeid&ename=' + escape(ename),
                timeout: '20000',
                error: function() {
                    alert("加载栋阁失败！");
                }, success: function(json) {
                    if (json != "") {
                        loadBuildCallBack(json);
                    }
                }
            });
        }

        function loadBuildCallBack(response) {
            var json = eval("(" + response + ")");
            var record = json.record;

            document.getElementById("slBuild").options.length = 0;
            $("#slBuild").html("");
            var obj = document.getElementById("slBuild");

            LexunJS.selectAddOption(obj, "请选择", 0);

            if (record == null || record.length == 0)
                 return;
            var recordLength = record.length;
            for (var i = 0; i < recordLength; i++) {
                var sName = record[i].finalname;
                var sValue = record[i].id;

                LexunJS.selectAddOption(obj, sName, sValue);
            }
        }


        //加载栋阁
        function ShowBuildList(currentPage) {
            $("#hRoomId").val(""); //清空房号ID
            $("#hID").val("");
            $("#divRoomNoList").html("");//清空房号列表

            var ename = $("#hEstateName").val();        // 楼盘名称

            if ((typeof (ename) == "undefined"))
                ename = "";
           
            $.ajax({
                type: 'POST',
                url: '../Handler/HandlerIndex.ashx',
                data: 'act=Build_ListByName&ename=' + escape(ename) + '&page=' + currentPage+'&pagesize='+pageSize,
                timeout: '20000',
                error: function() {
                    alert("加载栋阁失败！");
                }, success: function(json) {
                if (json != "") {
                        loadBuildListCallBack(json, ename);
                    }
                }
            });
        }

        function loadBuildListCallBack(response, name) {
            var json = eval("(" + response + ")");
            var record = json.record;

            var page = json.page;

            currentPage = page.currentpage;
            pageall = parseInt(page.pageall);
            total = page.total;
            $("#divList").html(""); // 清空列表


            if (record == null || record.length == 0)
                return;
            var recordLength = record.length;
            var arr = [];
            arr.push("<table id='table1' width='100%' border='0' cellpadding='0' cellspacing='1' bgcolor='#a8c7ce'>");
            arr.push("<tr>");
            arr.push("<td height='25' bgcolor='d3eaef' class='STYLE10'>");
            arr.push("<input type=\"checkbox\" name=\"checkboxAll\" id=\"checkboxAll\" onclick=\"cbSelectAll()\" />");
            arr.push("</td>");

            arr.push("<td height='25' bgcolor='d3eaef' class='STYLE10'>");
            arr.push("序号");
            arr.push("</td>");
            arr.push("<td height='25' bgcolor='d3eaef' class='STYLE10'>");
            arr.push("栋阁名称");
            arr.push("</td>");
            arr.push("<td height='25' bgcolor='d3eaef' class='STYLE10'>");
            arr.push("楼盘名称");
            arr.push("</td>");

            arr.push("<td height='25' bgcolor='d3eaef' class='STYLE10'>");
            arr.push("基本操作");
            arr.push("</td>");
            
            for (var i = 0; i < recordLength; i++) {

                if (i % 2 == 0)
                    arr.push("<tr id='tr_" + record[i].id + "' bgcolor='#FFFFFF' style='cursor: pointer;' >");
                else
                    arr.push("<tr id='tr_" + record[i].id + "' bgcolor='#EEEDED' style='cursor: pointer;' >");

                arr.push("<td height='20' class='STYLE6'>");
                arr.push("<input type='checkbox' name='checkbox_" + record[i].id + "' id='" + record[i].id + "' onclick=\"cbSelect(this, " + record[i].id + ");RoomList("+record[i].id+")\" />");
                arr.push("</td>");

                arr.push("<td height='20' class='STYLE6'>");
                arr.push(record[i].id);
                arr.push("</td>");

                arr.push("<td height='20' style='text-align: left;'>");
                arr.push(record[i].name);
                arr.push("</td>");

                arr.push("<td height='20' class='STYLE6'>");
                arr.push(name);
                arr.push("</td>");
                
                arr.push("<td height='20' class='STYLE6'>");
                arr.push("<a href='javascript:UpdateBuildParentId(" + record[i].id + ")'>设为一级栋阁</a>|");
                arr.push("<a href='javascript:DropBuild(" + record[i].id + ")'>删除</a>");

                arr.push("</td>");
                
                arr.push("</tr>");
            }
            arr.push("</table>");
            $("#divList").html(arr.join('')); // 显示列表
            $("#divPage").html(""); // 清空


            var pageHtml = LexunJS.showPage2(currentPage, pageall, "ShowBuildList"); // 分页
            $("#divPage").html(pageHtml);

            
           
        }


        // 单选栋阁
        function cbSelect(obj, objvalue) {
            if (obj.checked) {
                LexunJS.addOrCutData(1, "hID", objvalue);
            }
            else {
                LexunJS.addOrCutData(0, "hID", objvalue);
            }
        }
        //单选房号
        function cbRoomSelect(obj, objvalue) {
            if (obj.checked) {
                LexunJS.addOrCutData(1, "hRoomID", objvalue);
            }
            else {
                LexunJS.addOrCutData(0, "hRoomID", objvalue);
            }
        }
        
        // 全选
        function cbSelectAll() {
            document.getElementById("hID").value = "";
            var cbAll = document.getElementById("checkboxAll");
            var checkList = document.getElementsByTagName("input");

            if (cbAll.checked) {
                for (var i = 0; i < checkList.length; i++) {
                    if (checkList[i].type == "checkbox") {
                        checkList[i].checked = true;
                        if (parseInt(checkList[i].id) > 0) LexunJS.addOrCutData(1, "hID", checkList[i].id);
                    }
                }
            }
            else {
                for (var i = 0; i < checkList.length; i++) {
                    if (checkList[i].type == "checkbox") {
                        checkList[i].checked = false;
                        if (parseInt(checkList[i].id) > 0) LexunJS.addOrCutData(0, "hID", checkList[i].id);
                    }
                }
            }
        }

        function UpdateBuildParentId(id) {
            hiConfirm("您确定要设为一级栋阁，请谨慎操作！", "确认框", function(result) {
                if (result) {
                    $.ajax({
                        type: 'POST',
                        url: '../Handler/HandlerIndex.ashx',
                        data: 'act=UpdateBuildParentId&id=' + id,
                        timeout: '10000',
                        error: function() {
                            alert("系统繁忙，请稍候后试！");
                        },
                        success: function(json) {
                            alert(json);
                            ShowBuildList(currentPage);
                        }
                    });
                }
            });
         }

         function RoomList(bid) {
             $.ajax({
                 type: 'POST',
                 url: '../Handler/HandlerRoomNo.ashx',
                 data: 'act=SelectRoomNoList&bid=' + bid,
                 timeout: '10000',
                 error: function() {
                     alert("系统繁忙,请稍候后试！");
                 }, success: function(json) {
                     listCallBack(json);
                 }
             });

         }

         /*
         功能: 将返回的json数据进行排版
         json: json数据
         */

         function listCallBack(response) {
             $("#divRoomNoList").html("");///清空房号列表
             var json = eval("(" + response + ")");
             var record = json.record;

             if (record == null || record.length == 0) {
                 $("#divRoomNoList").html("<font color='red'>&nbsp;系统内暂无您查询的信息!</font>");
                 return;
             }

             var arr = [];
             
             arr.push("<div id='div1' style='margin-top: 2px; margin-bottom: 2px;'><table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td height='24' bgcolor='#353c44'><table width='100%' border='0'cellspacing='0' cellpadding='0'><tr><td><img src='../images/tb.gif' width='14' height='14' /><span class='STYLE1'>请选择需要移走的房号</span></td></tr></table></td></tr></table></div>");
             arr.push("<table id='table1' width='100%' border='0' cellpadding='0' cellspacing='1' bgcolor='#a8c7ce'>");
             arr.push("<tr>");
             arr.push("<td height='25' width='30px' bgcolor='d3eaef' class='STYLE6'>");
             arr.push("楼层");
             arr.push("</td>");
             arr.push("<td height='25' width='30px' bgcolor='d3eaef' class='STYLE6'>");
             arr.push("用途");
             arr.push("</td>");
             arr.push("<td height='25' bgcolor='d3eaef' class='STYLE6'>");
             arr.push("房号");
             arr.push("</td>");
             arr.push("</tr>");

             var recordLength = record.length;
             var floor1 = -9999;
             var floor2 = 0;
             for (var i = 0; i < recordLength; i++) {
                 floor2 = record[i].floor;

                 if (floor1 != floor2) {
                     if (floor1 != -9999) {
                         arr.push("</td>");
                         arr.push("</tr>");
                     }
                     floor1 = floor2
                     if (i % 2 == 0)
                         arr.push("<tr id='tr_" + record[i].id + "' bgcolor='#FFFFFF'>");
                     else
                         arr.push("<tr id='tr_" + record[i].id + "' bgcolor='#EEEDED'>");

                     arr.push("<td height='20' style='text-align: left;'>");
                     arr.push(floor2);
                     arr.push("</td>");
                     arr.push("<td height='20' style='text-align: left;'>");

                     var useValue = "";
                     var useStr = record[i].usage;
                     if (useStr == "1")
                         useValue = "住宅";
                     else if (useStr == "2")
                         useValue = "商铺";
                     else if (useStr == "3")
                         useValue = "写字楼";
                     else if (useStr == "4")
                         useValue = "商住";
                     else if (useStr == "5")
                         useValue = "仓库";
                     else if (useStr == "6")
                         useValue = "厂房";
                     else if (useStr == "7")
                         useValue = "地皮";
                     else if (useStr == "8")
                         useValue = "项目盘";
                     else if (useStr == "9")
                         useValue = "其他*";
                     else
                         useValue = useStr;
                     arr.push(useValue);
                     arr.push("</td>");
                     arr.push("<td height='20' style='text-align: left;'>");
                 }

                 if (record[i].bstatus == 1) {
                     arr.push("<font style = 'background:#FF99FF' >");
                     arr.push("<input type='checkbox' name='checkboxroom_" + record[i].id + "' id='checkboxroom" + record[i].id + "' onclick=\"cbRoomSelect(this, " + record[i].id + ")\" /><strong>" + record[i].name + "</strong>&nbsp;&nbsp;&nbsp;");

                 }
                 else if (record[i].bstatus == 2) {
                     arr.push("<font style = 'background:Yellow' >");
                     arr.push("<input type='checkbox' name='checkboxroom_" + record[i].id + "' id='checkboxroom" + record[i].id + "' onclick=\"cbRoomSelect(this, " + record[i].id + ")\" /><strong>" + record[i].name + "</strong>&nbsp;&nbsp;&nbsp;");

                 }
                 else if (record[i].bstatus == 3) {
                     arr.push("<font style = 'background:#66CCFF' >");
                     arr.push("<input type='checkbox' name='checkboxroom_" + record[i].id + "' id='checkboxroom" + record[i].id + "' onclick=\"cbRoomSelect(this, " + record[i].id + ")\" /><strong>" + record[i].name + "</strong>&nbsp;&nbsp;&nbsp;");

                 }
                 else {
                     arr.push("<font>");
                     arr.push("<input type='checkbox' name='checkboxroom_" + record[i].id + "' id='checkboxroom" + record[i].id + "' onclick=\"cbRoomSelect(this, " + record[i].id + ")\" /><strong>" + record[i].name + "</strong><a href=\"javascript:DeleteName(" + record[i].id + ");\" value='" + record[i].name + "' style='color:red;'>删除</a>&nbsp;&nbsp;&nbsp;");

                 }

                 arr.push("</font>");
             }
             arr.push("</table>");
             $("#divRoomNoList").html(arr.join('')); // 显示列表
         }
         //删除房号
         function DeleteName(id) {
             hiConfirm("您确定要删除该房号，请谨慎操作！", "确认框", function(result) {
                 if (result) {
                     $.ajax({
                         type: 'POST',
                         url: '../Handler/HandlerRoomNo.ashx',
                         data: 'act=del&id=' + id,
                         timeout: '10000',
                         error: function() {
                             alert("系统繁忙，请稍候后试！");
                         },
                         success: function(json) {
                             showDetailCallBack(json);
                         }
                     });
                 }
             });
         }
         function showDetailCallBack(response) {
             var json = eval("(" + response + ")");
             if (json > 0) {
                 var bid = $("#hID").val();
                 if (bid != "") {
                     var arr = bid.split("|");
                     RoomList(arr[0]);
                 }
             } else {
                 alert("删除失败！");
             }
         }
        
        
        ///移动栋阁
         function RemoveBuild() {
             var parentId = document.getElementById("slBuild").value;//需要移动到哪个栋阁下面
             if (parentId == "") {
                 alert("请选择栋阁");
                 return;
             }



             var id = document.getElementById("hID").value; //需要移动的栋阁
             if (id == "") {
                 alert("请选择需要移动的栋阁");
                 return;
             }
             
             hiConfirm("您确定要移动栋阁，请谨慎操作！", "确认框", function(result) {
                 if (result) {
                     $.ajax({
                         type: 'POST',
                         url: '../Handler/HandlerIndex.ashx',
                         data: 'act=RemoveBuildParentId&id=' + id + "&parentId=" + parentId,
                         timeout: '10000',
                         error: function() {
                         alert("系统繁忙，请稍候后试！");
                         $("#hID").val("");

                         },
                         success: function(json) {
                          alert(json);
                         $("#hID").val("");

                         ShowBuildList(currentPage);
                         }
                     });
                 }
             });
             
             
          }

          ///移动房号
          function RemoveRoomNo() {
              var Bid = document.getElementById("slBuild").value; //需要移动到哪个栋阁下面
               if(Bid == "") {
                  alert("请选择栋阁");
                  return;
                }

                var id = document.getElementById("hRoomId").value; //需要移动的房号
                if (id == "") {
                    alert("请选择需要移动的房号");
                    return;
                }
                hiConfirm("您确定要移动房号，请谨慎操作！", "确认框", function(result) {
                    if (result) {
                        $.ajax({
                            type: 'POST',
                            url: '../Handler/HandlerIndex.ashx',
                            data: 'act=RemoveRoomNoByBId&id=' + id + "&bid=" + Bid,
                            timeout: '10000',
                            error: function() {
                                alert("系统繁忙，请稍候后试！");
                                $("#hRoomId").val("");
                            },
                            success: function(json) {
                                alert(json);
                                $("#hRoomId").val("");
                                var bid = $("#hID").val();
                                $("#hID").val("");
                                if (bid != "") {
                                    var arr = bid.split("|");
                                    RoomList(arr[0]);
                                }

                            }
                        });
                    }
                });


            }
            ///删除栋阁
            function DropBuild(id) {
                hiConfirm("您确定要删除该栋阁，请谨慎操作！", "确认框", function(result) {
                    if (result) {
                        $.ajax({
                            type: 'POST',
                            url: '../Handler/HandlerIndex.ashx',
                            data: 'act=UpdateBuild&id=' + id,
                            timeout: '10000',
                            error: function() {
                                alert("系统繁忙，请稍候后试！");
                            },
                            success: function(json) {
                            alert(json);
                            ShowBuildList(currentPage);
                            }
                        });
                    }
                });
            }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div id="divSearch" style="margin-top: 5px; text-align: center;">
        <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#a8c7ce">
            <tr>
                <td colspan="2" style="text-align: left; background-color: #FFFFFF; cursor: pointer;" valign="middle">
                 <strong>合并栋阁</strong>
                </td>
            </tr>
            <tr>
                <td colspan="2" style="text-align: left; background-color: #FFFFFF; cursor: pointer;" valign="middle">
                    楼盘名称:&nbsp;&nbsp;&nbsp;
                    <uc1:Estate_Autocomplete ID="Estate_Autocomplete1" runat="server" />
                &nbsp;&nbsp;&nbsp;&nbsp;
                    <input id="btnSearch" class="button_bak" type="button" value="查询" onclick="return Search()" />
                    &nbsp;&nbsp;&nbsp;需要移动到的栋阁:
                    <asp:DropDownList ID="slBuild"  Width="20%" name="slBuild" runat="server">
                    </asp:DropDownList>    
                               
                    &nbsp;    
                               
                    <input id="btnSave" type="button" value="移动栋阁" class="button_bak"  onclick="RemoveBuild();"/>&nbsp;
                    
                    <input id="btnRemove" type="button" value="移动房号" class="button_bak"  onclick="RemoveRoomNo();"/>&nbsp;
    
                
    
                </td>
            </tr>
            <tr>
                <td   style="text-align: left; background-color: #FFFFFF; cursor: pointer; " valign="middle">
                 
                </td>
                
               
            </tr>
        </table>
    </div>
    <div id="divHead" style="margin-top: 2px; margin-bottom: 2px;">
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td height="24" bgcolor="#353c44">
                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                            <td>
                                <img src="../images/tb.gif" width="14" height="14" /><span class="STYLE1">请选择需要合并的栋阁</span>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </div>
    
    <div id="divList" >
    </div>
    <div id="divPage"></div>
    
    
    
    <div id="divRoomNoList" >
                
    </div>
    
    
    <input id="hID" name="hID" runat="server"   type="hidden" /><!--栋阁ID->
    <input id="hRoomId" name="hRoomId" runat="server" type="hidden"/><!--房号ID->
    </form>
    
</body>


<script src="../js/LexunJS.js" type="text/javascript"></script>
<script src="../js/jShowDiv.js" type="text/javascript"></script>

</html>
